﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GeneralLibs;
using Lists;
using System.Linq;

namespace BasicForms
{
    public partial class FrmCauHinhTaiKhoanMacDinh : BasicForms.FrmOKCancel
    {
        public FrmCauHinhTaiKhoanMacDinh()
        {
            InitializeComponent();
        }

        private void FrmCauHinhTaiKhoanMacDinh_Load(object sender, EventArgs e)
        {
            if (DesignMode) return;
            #region cmbTaiKhoanVatDauVao
            cmbTaiKhoanVatDauVao.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanVatDauVao.DisplayColumn = "SoHieu";
            cmbTaiKhoanVatDauVao.ValueColumn = "ID";
            cmbTaiKhoanVatDauVao.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanVatDauVao.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanVatDauRa
            cmbTaiKhoanVatDauRa.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanVatDauRa.DisplayColumn = "SoHieu";
            cmbTaiKhoanVatDauRa.ValueColumn = "ID";
            cmbTaiKhoanVatDauRa.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanVatDauRa.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanChietKhauThuongMai
            cmbTaiKhoanChietKhauThuongMai.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanChietKhauThuongMai.DisplayColumn = "SoHieu";
            cmbTaiKhoanChietKhauThuongMai.ValueColumn = "ID";
            cmbTaiKhoanChietKhauThuongMai.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanChietKhauThuongMai.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanDoanhThuBanHangVaCungCapDichVu
            cmbTaiKhoanDoanhThuBanHangVaCungCapDichVu.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanDoanhThuBanHangVaCungCapDichVu.DisplayColumn = "SoHieu";
            cmbTaiKhoanDoanhThuBanHangVaCungCapDichVu.ValueColumn = "ID";
            cmbTaiKhoanDoanhThuBanHangVaCungCapDichVu.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanDoanhThuBanHangVaCungCapDichVu.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanHangBanBiTraLai
            cmbTaiKhoanHangBanBiTraLai.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanHangBanBiTraLai.DisplayColumn = "SoHieu";
            cmbTaiKhoanHangBanBiTraLai.ValueColumn = "ID";
            cmbTaiKhoanHangBanBiTraLai.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanHangBanBiTraLai.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanThanhToanNhapLaiHangDaBan
            cmbTaiKhoanThanhToanHangBanTraLai.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanThanhToanHangBanTraLai.DisplayColumn = "SoHieu";
            cmbTaiKhoanThanhToanHangBanTraLai.ValueColumn = "ID";
            cmbTaiKhoanThanhToanHangBanTraLai.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanThanhToanHangBanTraLai.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanThanhToanHangMuaTraLai
            cmbTaiKhoanThanhToanHangMuaTraLai.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanThanhToanHangMuaTraLai.DisplayColumn = "SoHieu";
            cmbTaiKhoanThanhToanHangMuaTraLai.ValueColumn = "ID";
            cmbTaiKhoanThanhToanHangMuaTraLai.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanThanhToanHangMuaTraLai.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanNoTienThuVe
            cmbTaiKhoanNoTienThuVe.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanNoTienThuVe.DisplayColumn = "SoHieu";
            cmbTaiKhoanNoTienThuVe.ValueColumn = "ID";
            cmbTaiKhoanNoTienThuVe.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanNoTienThuVe.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanCoDoanhThu
            cmbTaiKhoanCoDoanhThu.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanCoDoanhThu.DisplayColumn = "SoHieu";
            cmbTaiKhoanCoDoanhThu.ValueColumn = "ID";
            cmbTaiKhoanCoDoanhThu.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanCoDoanhThu.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanCoVat
            cmbTaiKhoanCoVat.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanCoVat.DisplayColumn = "SoHieu";
            cmbTaiKhoanCoVat.ValueColumn = "ID";
            cmbTaiKhoanCoVat.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanCoVat.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanNoGiaVon
            cmbTaiKhoanNoGiaVon.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanNoGiaVon.DisplayColumn = "SoHieu";
            cmbTaiKhoanNoGiaVon.ValueColumn = "ID";
            cmbTaiKhoanNoGiaVon.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanNoGiaVon.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanCoXuatKho
            cmbTaiKhoanCoXuatKho.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanCoXuatKho.DisplayColumn = "SoHieu";
            cmbTaiKhoanCoXuatKho.ValueColumn = "ID";
            cmbTaiKhoanCoXuatKho.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanCoXuatKho.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanTienMat
            cmbTaiKhoanTienMat.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanTienMat.DisplayColumn = "SoHieu";
            cmbTaiKhoanTienMat.ValueColumn = "ID";
            cmbTaiKhoanTienMat.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanTienMat.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanTienGuiNganHang
            cmbTaiKhoanTienGuiNganHang.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanTienGuiNganHang.DisplayColumn = "SoHieu";
            cmbTaiKhoanTienGuiNganHang.ValueColumn = "ID";
            cmbTaiKhoanTienGuiNganHang.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanTienGuiNganHang.AddVisibleColumn("Ten", "Tên");
            #endregion


            #region cmbTaiKhoanGiaMuaHangHoa
            cmbTaiKhoanGiaMuaHangHoa.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanGiaMuaHangHoa.DisplayColumn = "SoHieu";
            cmbTaiKhoanGiaMuaHangHoa.ValueColumn = "ID";
            cmbTaiKhoanGiaMuaHangHoa.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanGiaMuaHangHoa.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanGhiCoNhapKho
            cmbTaiKhoanGhiCoNhapKho.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanGhiCoNhapKho.DisplayColumn = "SoHieu";
            cmbTaiKhoanGhiCoNhapKho.ValueColumn = "ID";
            cmbTaiKhoanGhiCoNhapKho.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanGhiCoNhapKho.AddVisibleColumn("Ten", "Tên");
            #endregion


            #region cmbTaiKhoanGhiNoXuatKho
            cmbTaiKhoanGhiNoXuatKho.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanGhiNoXuatKho.DisplayColumn = "SoHieu";
            cmbTaiKhoanGhiNoXuatKho.ValueColumn = "ID";
            cmbTaiKhoanGhiNoXuatKho.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanGhiNoXuatKho.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanPhaiThuKhacHang
            cmbTaiKhoanPhaiThuKhacHang.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanPhaiThuKhacHang.DisplayColumn = "SoHieu";
            cmbTaiKhoanPhaiThuKhacHang.ValueColumn = "ID";
            cmbTaiKhoanPhaiThuKhacHang.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanPhaiThuKhacHang.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanPhaiTraNhaCungCap
            cmbTaiKhoanPhaiTraNhaCungCap.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanPhaiTraNhaCungCap.DisplayColumn = "SoHieu";
            cmbTaiKhoanPhaiTraNhaCungCap.ValueColumn = "ID";
            cmbTaiKhoanPhaiTraNhaCungCap.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanPhaiTraNhaCungCap.AddVisibleColumn("Ten", "Tên");
            #endregion


            #region cmbTaiKhoanThuNhapKhac
            cmbTaiKhoanThuNhapKhac.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanThuNhapKhac.DisplayColumn = "SoHieu";
            cmbTaiKhoanThuNhapKhac.ValueColumn = "ID";
            cmbTaiKhoanThuNhapKhac.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanThuNhapKhac.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbTaiKhoanChiPhiKhac
            cmbTaiKhoanChiPhiKhac.DataSource = DanhMucTaiKhoan.GetByLoaiTaiKhoan(LoaiTaiKhoan.NoiBang | LoaiTaiKhoan.TaiKhoanCapThapNhat).DataView;
            cmbTaiKhoanChiPhiKhac.DisplayColumn = "SoHieu";
            cmbTaiKhoanChiPhiKhac.ValueColumn = "ID";
            cmbTaiKhoanChiPhiKhac.AddVisibleColumn("SoHieu", "Số hiệu");
            cmbTaiKhoanChiPhiKhac.AddVisibleColumn("Ten", "Tên");
            #endregion

            cmbTaiKhoanVatDauVao.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("VatDauVao");
            cmbTaiKhoanVatDauRa.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("VatDauRa");
            cmbTaiKhoanChietKhauThuongMai.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("ChietKhauThuongMai");
            cmbTaiKhoanDoanhThuBanHangVaCungCapDichVu.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("DoanhThuBanHangVaCungCapDichVu");
            cmbTaiKhoanHangBanBiTraLai.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("HangBanBiTraLai");
            cmbTaiKhoanThanhToanHangBanTraLai.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("ThanhToanHangBanTraLai");
            cmbTaiKhoanThanhToanHangMuaTraLai.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("ThanhToanHangMuaTraLai");

            cmbTaiKhoanNoTienThuVe.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("BanLe_NoTienThuVe");
            cmbTaiKhoanCoDoanhThu.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("BanLe_CoDoanhThu");
            cmbTaiKhoanCoVat.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("BanLe_CoVat");
            cmbTaiKhoanNoGiaVon.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("BanLe_NoGiaVon");
            cmbTaiKhoanCoXuatKho.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("BanLe_CoXuatKho");

            cmbTaiKhoanGhiNoXuatKho.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("QLKho_GhiNoXuatKho");
            cmbTaiKhoanGhiCoNhapKho.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("QLKho_GhiCoNhapKho");

            cmbTaiKhoanTienMat.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("TienMat");
            cmbTaiKhoanTienGuiNganHang.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("TienGuiNganHang");

            cmbTaiKhoanGiaMuaHangHoa.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("GiaMuaHangHoa");

            cmbTaiKhoanPhaiThuKhacHang.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("PhaiThuKhachHang");
            cmbTaiKhoanPhaiTraNhaCungCap.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("PhaiTraNhaCungCap");

            cmbTaiKhoanThuNhapKhac.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("ThuNhapKhac");
            cmbTaiKhoanChiPhiKhac.EditValue = DanhMucCauHinhTaiKhoanMacDinh.Instance.GetTaiKhoanIDByTinhChat("ChiPhiKhac");
        }

        protected override void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (!(cmbTaiKhoanVatDauVao.EditValue is Guid))
                {
                    MessageBox.Show("Phải chọn tài khỏan ghi nợ giá vốn");
                    cmbTaiKhoanVatDauVao.Focus();
                    return;
                }
                if (!(cmbTaiKhoanVatDauRa.EditValue is Guid))
                {
                    MessageBox.Show("Phải chọn tài khỏan ghi có xuất kho");
                    cmbTaiKhoanVatDauRa.Focus();
                    return;
                }
                if (!(cmbTaiKhoanVatDauRa.EditValue is Guid))
                {
                    MessageBox.Show("Phải chọn tài khỏan chiết khấu thương mại");
                    cmbTaiKhoanVatDauRa.Focus();
                    return;
                }

                #region TaiKhoanMacDinh
                if (cmbTaiKhoanVatDauVao.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("VatDauVao", (Guid)cmbTaiKhoanVatDauVao.EditValue);
                if (cmbTaiKhoanVatDauRa.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("VatDauRa", (Guid)cmbTaiKhoanVatDauRa.EditValue);
                if (cmbTaiKhoanChietKhauThuongMai.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("ChietKhauThuongMai", (Guid)cmbTaiKhoanChietKhauThuongMai.EditValue);
                if (cmbTaiKhoanDoanhThuBanHangVaCungCapDichVu.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("DoanhThuBanHangVaCungCapDichVu", (Guid)cmbTaiKhoanDoanhThuBanHangVaCungCapDichVu.EditValue);
                if (cmbTaiKhoanHangBanBiTraLai.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("HangBanBiTraLai", (Guid)cmbTaiKhoanHangBanBiTraLai.EditValue);
                if (cmbTaiKhoanThanhToanHangBanTraLai.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("ThanhToanHangBanTraLai", (Guid)cmbTaiKhoanThanhToanHangBanTraLai.EditValue);
                if (cmbTaiKhoanThanhToanHangMuaTraLai.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("ThanhToanHangMuaTraLai", (Guid)cmbTaiKhoanThanhToanHangMuaTraLai.EditValue);
                #endregion

                #region TaiKhoanMacDinhBanLe
                if (cmbTaiKhoanNoTienThuVe.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("BanLe_NoTienThuVe", (Guid)cmbTaiKhoanNoTienThuVe.EditValue);
                if (cmbTaiKhoanNoTienThuVe.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("BanLe_NoTienThuVe", (Guid)cmbTaiKhoanNoTienThuVe.EditValue);
                if (cmbTaiKhoanCoDoanhThu.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("BanLe_CoDoanhThu", (Guid)cmbTaiKhoanCoDoanhThu.EditValue);
                if (cmbTaiKhoanCoVat.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("BanLe_CoVat", (Guid)cmbTaiKhoanCoVat.EditValue);
                if (cmbTaiKhoanNoGiaVon.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("BanLe_NoGiaVon", (Guid)cmbTaiKhoanNoGiaVon.EditValue);
                if (cmbTaiKhoanCoXuatKho.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("BanLe_CoXuatKho", (Guid)cmbTaiKhoanCoXuatKho.EditValue);
                #endregion

                #region QuanLyQuy
                if (cmbTaiKhoanTienMat.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("TienMat", (Guid)cmbTaiKhoanTienMat.EditValue);
                if (cmbTaiKhoanTienGuiNganHang.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("TienGuiNganHang", (Guid)cmbTaiKhoanTienGuiNganHang.EditValue);
                #endregion

                #region QuanLyKho
                if (cmbTaiKhoanGiaMuaHangHoa.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("GiaMuaHangHoa", (Guid)cmbTaiKhoanGiaMuaHangHoa.EditValue);
                if (cmbTaiKhoanGhiCoNhapKho.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("QLKho_GhiCoNhapKho", (Guid)cmbTaiKhoanGhiCoNhapKho.EditValue);
                if (cmbTaiKhoanGhiNoXuatKho.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("QLKho_GhiNoXuatKho", (Guid)cmbTaiKhoanGhiNoXuatKho.EditValue);
                #endregion

                #region CongNo
                if (cmbTaiKhoanPhaiThuKhacHang.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("PhaiThuKhachHang", (Guid)cmbTaiKhoanPhaiThuKhacHang.EditValue);
                if (cmbTaiKhoanPhaiTraNhaCungCap.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("PhaiTraNhaCungCap", (Guid)cmbTaiKhoanPhaiTraNhaCungCap.EditValue);
                #endregion

                if (cmbTaiKhoanThuNhapKhac.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("ThuNhapKhac", (Guid)cmbTaiKhoanThuNhapKhac.EditValue);
                if (cmbTaiKhoanChiPhiKhac.EditValue is Guid)
                    DanhMucCauHinhTaiKhoanMacDinh.Instance.Set("ChiPhiKhac", (Guid)cmbTaiKhoanChiPhiKhac.EditValue);

                DanhMucCauHinhTaiKhoanMacDinh.Instance.UpdateToDB();

                Close();
            }
            catch (Exception ex)
            {
                BasicForms.FrmExceptionNotifier.ShowAndLog(ex);
            }
            
        }
    }
}
